package org.feiye.studyday14;

public class Company {
	public String name;
	public String address;
	public String phoneNumber;
	public String range;
	public Staff[] staff = new Staff[100];

	public Company() {
	}

	public Company(String name, String address, String phoneNumber, String range) {
		this.name = name;
		this.address = address;
		this.phoneNumber = phoneNumber;
		this.range = range;
	}

	// 公司和员工的信息
	public void showinfo() {
		System.out.print("公司的名称是：" + name);
		System.out.print("，公司的电话号码是：" + phoneNumber);
		System.out.print("，公司的地址是：" + address);
		System.out.println("，公司的经营范围：" + range);
		System.out.println("，公司员工的信息如下：");
		for (int i = 0; i < staff.length; i++) {
			if (staff[i] != null) {
				staff[i].showinfo();
				System.out.println();
			}
		}
	}

	// 招聘新人
	public boolean hire(Staff newStaff) {
		for (int i = 0; i < staff.length; i++) {
			if (staff[i] == null) {
				staff[i] = newStaff;
				return true;
			}
		}
		return false;
	}

	// 辞退员工
	public boolean fire(String num) {
		for (int i = 0; i < staff.length; i++) {
			if (staff[i] != null && staff[i].cNumber.equals(num)) {
				for (int j = i + 1; j < staff.length; j++) {
					staff[j - 1] = staff[j];
				}
				staff[staff.length - 1] = null;
				return true;
			}
		}
		return false;
	}

	// 找到薪水最高的人
	public Staff findTopSalary() {
		if (staff[0] == null)// 中间没有空挡的情况
			return null;
		int index = 0;
		double max = staff[0].salary;
		for (int i = 0; i < staff.length; i++) {
			if (staff[i] != null && max < staff[i].salary) {
				max = staff[i].salary;
				index = i;
			}
		}
		return staff[index];
	}

	// 所有的员工涨薪百分之,按照百分比
	public void incrSal(double percent) {
		for (int i = 0; i < staff.length; i++) {
			if (staff[i] != null) {
				staff[i].salary += (staff[i].salary) * percent;
			}
		}

	}

}
